#region Copyright
//       Copyright (c) 2009 - Antoine Jaussoin - http://www.jaussoin.com/blog/
// 
//        This program is free software: you can redistribute it and/or modify
//        it under the terms of the GNU General Public License as published by
//        the Free Software Foundation, either version 3 of the License, or
//        (at your option) any later version.
// 
//        This program is distributed in the hope that it will be useful,
//        but WITHOUT ANY WARRANTY; without even the implied warranty of
//        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//        GNU General Public License for more details.
// 
//        You should have received a copy of the GNU General Public License
//        along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Collections;

namespace FT.Architecture.Repositories
{
    /// <summary>
    /// Interface for a non-generic Repository, that will work with Type objects instead of generics.
    /// </summary>
    public interface INonGenericRepository
    {
        /// <summary>
        /// Get an object by its id and its type
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        object GetById(object id, Type type);

        /// <summary>
        /// Get an object by the value of one of its member
        /// </summary>
        /// <param name="memberValue"></param>
        /// <param name="memberName"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        object GetByMember(object memberValue, string memberName, Type type);

        /// <summary>
        /// Get all entities of the specified type
        /// </summary>
        /// <returns></returns>
        IList GetAll(Type type);

        /// <summary>
        /// Returns the number of entities of a given type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        long GetCount(Type type);

        /// <summary>
        /// Get a random object of the given type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        object GetRandom(Type type);

        /// <summary>
        /// Save an entity: Make it persistent, as opposed to transient
        /// </summary>
        /// <param name="entity"></param>
        void Save(object entity);

        /// <summary>
        /// Delete an entity, but doesn't null the ID on it.
        /// </summary>
        /// <param name="entity"></param>
        void Delete(object entity);

        /// <summary>
        /// Un-proxy an object
        /// </summary>
        /// <param name="proxiedEntity"></param>
        /// <returns></returns>
        object UnProxy(object proxiedEntity);

        /// <summary>
        /// Get the concrete class of an object, from a proxied version
        /// </summary>
        /// <param name="proxiedEntity"></param>
        /// <returns></returns>
        Type GetConcreteType(object proxiedEntity);

        /// <summary>
        /// Search a list of entities. This is mainly used by <c>NSelector</c>
        /// </summary>
        /// <param name="searchText"></param>
        /// <param name="propertiesToSearchOn"></param>
        /// <param name="displayProperties"></param>
        /// <param name="orderByProperty"></param>
        /// <param name="orderByDirection"></param>
        /// <param name="type"></param>
        /// <param name="firstResult"></param>
        /// <param name="maxResult"></param>
        /// <returns></returns>
        IList SearchInObject(string searchText, string propertiesToSearchOn, string displayProperties,
                                    string orderByProperty, string orderByDirection, string type,
                                    int firstResult, int maxResult);

        /// <summary>
        /// Count the number of objects matching the <paramref name="searchText"/> for the given type and the given property
        /// </summary>
        /// <param name="searchText"></param>
        /// <param name="propertiesToSearchOn"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        int CountInObject(string searchText, string propertiesToSearchOn, string type);
    }
}
